#include "vertex_buffer.h"
using namespace krryn::view;

vertex_format::vertex_format() : m_SizeInBytes(0) {}

int vertex_format::append_element(size_t a_OffsetInBytes, element_type a_Element, element_semantic a_Semantic, unsigned short a_Index){
	vertex_element v = {a_OffsetInBytes, a_Element, a_Semantic, a_Index};
	m_Elements.push_back(v);

	switch(a_Element){
		case type_float1:         m_SizeInBytes = 1 * sizeof(float); break;
		case type_float2:         m_SizeInBytes = 2 * sizeof(float); break;
		case type_float3:         m_SizeInBytes = 3 * sizeof(float); break;
		case type_float4:         m_SizeInBytes = 4 * sizeof(float); break;
		case type_short1:         m_SizeInBytes = 1 * sizeof(short); break;
		case type_short2:         m_SizeInBytes = 2 * sizeof(short); break;
		case type_short3:         m_SizeInBytes = 3 * sizeof(short); break;
		case type_short4:         m_SizeInBytes = 4 * sizeof(short); break;
		case type_argb:           m_SizeInBytes = 1 * sizeof(unsigned int); break;
		case type_unsigned_byte4: m_SizeInBytes = 4 * sizeof(unsigned char); break;
		default: throw std::runtime_error("Unknown vertex element type");
	}

	return a_OffsetInBytes + m_SizeInBytes;
}

const vertex_element &vertex_format::at(size_t a_Index) { return m_Elements[a_Index]; }
size_t vertex_format::size() const { return m_Elements.size(); }

int vertex_format::get_size_in_bytes() const { return m_SizeInBytes; }